home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / nfpatchs.zip / ORIGIN.ASM < prev    next >
Assembly Source File  |  1991-08-23  |  3KB  |  128 lines

  1. ; File......: ORIGIN.ASM
  2. ; Author....: Steve Larsen
  3. ; CIS ID....: 76370,1532
  4. ; Date......: $Date:   23 Aug 1991 13:14:56  $
  5. ; Revision..: $Revision:   1.2  $
  6. ; Log file..: $Logfile:   E:/nanfor/src/origin.asv  $
  7. ;
  8. ; This is an original work by K. Stephan Larsen and is placed in
  9. ; the public domain.
  10. ;
  11. ; Modification history:
  12. ; ---------------------
  13. ;
  14. ; $Log:   E:/nanfor/src/origin.asv  $
  15. ;  
  16. ;     Rev 1.2   23 Aug 1991 13:14:56   GLENN
  17. ;  Bug fix around line 83, ax should have been bx.
  18. ;  
  19. ;     Rev 1.1   15 Aug 1991 23:08:00   GLENN
  20. ;  Forest Belt proofread/edited/cleaned up doc
  21. ;  
  22. ;     Rev 1.0   09 Jun 1991 00:40:16   GLENN
  23. ;  Initial revision.
  24. ;
  25.  
  26.  
  27.  
  28. ;
  29. ; $DOC$
  30. ; $FUNCNAME$
  31. ;    FT_ORIGIN()
  32. ; $CATEGORY$
  33. ;    Environment
  34. ; $ONELINER$
  35. ;    Report the drive, path and filename of the executing program
  36. ; $SYNTAX$
  37. ;    FT_ORIGIN() -> cString
  38. ; $ARGUMENTS$
  39. ;    None
  40. ; $RETURNS$
  41. ;    A string containing the full drive/directory/filename of
  42. ;    the currently executing file.
  43. ; $DESCRIPTION$
  44. ;    Often users will install multiple copies of application software,
  45. ;    especially on networks and in situations where the user is trying
  46. ;    to get around a copy protection scheme.
  47. ;
  48. ;    This function enables you to learn the name and source location 
  49. ;    of the currently executing file, so that you may take whatever
  50. ;    action you need to.
  51. ;
  52. ;    Requires DOS v3.xx and above.
  53. ; $EXAMPLES$
  54. ;    cMyFile := FT_ORIGIN()
  55. ;    
  56. ;    IF cMyFile <> "C:\APPDIR\MYFILE.EXE"
  57. ;       ?"Incorrect startup file.  Please remove/rename and start again"
  58. ;       QUIT
  59. ;    ENDIF
  60. ; $INCLUDE$
  61. ; $SEEALSO$
  62. ;    FT_WHEREIS() FT_TREE()
  63. ; $END$
  64. ;
  65.  
  66. TITLE ORIGIN.asm
  67.  
  68. PUBLIC FT_ORIGIN
  69.  
  70. EXTRN __retc:far
  71.  
  72. _NANFOR segment word public 'CODE'
  73.     ASSUME CS:_NANFOR
  74.  
  75. FT_ORIGIN       proc    far
  76.         push    ds              ; save Clipper's environment
  77.         push    es
  78.         push    di
  79.         push    si
  80.         push    bp
  81.         mov     bp, sp
  82.  
  83.         mov     ah, 62h         ; fetch segment address of PSP
  84.         int     21h
  85.         cld
  86.         mov     es, bx
  87.         mov     ax, es:[2Ch]    ; environment block seg is at PSP:2Ch
  88.         mov     es, ax          ; Env. Blk top in ES:DI, scan for 0000
  89.         xor     di, di
  90.         xor     ax, ax
  91.         mov     cx, 0FFFFh
  92. lf_1:   repne   scasb           ; scan for a null terminator
  93.         mov     bl, es:[di]     ; found one, now check for 2 nulls in a 
  94.         or      bl, bl          ;   row, means end of env. blk.
  95.         jnz     lf_1
  96.  
  97.         inc     di              ; now test for something, if there, that's
  98.         mov     ax, es:[di]     ;   our path.
  99.         or      ax, ax
  100.         jz      lf_2
  101.         inc     di              ; no path, point to a null
  102.         inc     di
  103.  
  104. lf_2:    push    es              ; save address of path for
  105.     push    di              ;  return to Clipper
  106.         pop     ax
  107.         pop     dx
  108.  
  109.         mov     sp, bp          ; housekeeping
  110.         pop     bp
  111.         pop     si
  112.         pop     di
  113.         pop     es
  114.         pop     ds
  115.  
  116.         push    dx              ; return path string to Clipper
  117.         push    ax
  118.  
  119.     call    __retc
  120.     add    sp,4
  121.  
  122.         ret
  123. FT_ORIGIN       endp
  124.  
  125. _NANFOR    ends
  126.     end
  127. 
  128.